<?php
class OrderController extends Controller{
    public $layout='//layouts/admin';

    public function actionListorder(){
        session_start();
        if($_SESSION['admin']){
            $modelorder = new Order();
            $list_custom = $modelorder->findAll();
            $this->render('Listorder',array('list_custom'=>$list_custom));
        }
    }

    public function actionPreshoworder(){
        session_start();
        if($_SESSION['admin']){
            if(is_numeric($_GET['id'])){
                echo $id = $_GET['id'];
                $modelorder = new Order();
                $item_order = $modelorder->findByPk($id);

                $modeldetail = new Orderdetail();
                $order_detail = $modeldetail->findAll("order_id = $id");

                $this->render('showinfoorder',array('item_order'=>$item_order, 'order_detail'=>$order_detail));
            }
        }
    }

    public function actionShipping(){
        session_start();
        if($_SESSION['admin'] && is_numeric($_GET['id'])){
            echo $id = $_GET['id'];
            $modelorder = Order::model()->findByPk($id);
            $modelorder ->status = 1;
            $modelorder->update();
            $this->redirect("index.php?r=admin/order/listorder");
        }
    }

    public function actionDelOrder(){
        session_start();
        if($_SESSION['admin']['lever']==1 && is_numeric($_GET['id'])){
            $id = $_GET['id'];
            $modelorder = Order::model()->findByPk($id);
            $modelorder->delete();
            $modeldetail = new Orderdetail();
            $modeldetail->deleteAll("order_id=$id");
            $this->redirect("index.php?r=admin/order/listorder");
        }
    }


}